
using UnityEngine;
using UnityEngine.SceneManagement;

public class SettingPanel : BasePanel<SettingPanel>
{
    public CustomGUIButton btkClose;
    public CustomGUISlider sldMusic;
    public CustomGUISlider sldSoundEffect;
    public CustomGUIToggle togMusic;
    public CustomGUIToggle togSoundEffect;

    // Start is called before the first frame update
    void Start()
    {
        sldMusic.changeValue += (value) =>
        {
            //处理音乐大小变化
            GameDataMgr.Instance.soundData.musicValue = value;
            BKMusic.Instance.ChangeValue(value);
        };
        sldSoundEffect.changeValue += (value) =>
        {
            //处理音效大小变化
            GameDataMgr.Instance.soundData.soundEffectValue = value;
        };
        togMusic.changeValue += (value) =>
        {
            //处理音乐开关
            GameDataMgr.Instance.soundData.isOnMusic = value;
            BKMusic.Instance.ChangeOpen(value);
        };
        togSoundEffect.changeValue += (value) =>
        {
            //处理音效开关
            GameDataMgr.Instance.soundData.isOnSoundEffect = value;
        };
        btkClose.clickEvent += () =>
        {
            Time.timeScale = 1;//恢复时间计时

            //保存数据
            PlayerPrefsDataMgr.Instance.SaveData(GameDataMgr.Instance.soundData, "Sound");
            //判断当前场景
            if (SceneManager.GetActiveScene().name == "BeginScene")
                BeginPanel.Instance.ShowMe();
            //关闭面板
            HideMe();
        };
        //默认隐藏
        HideMe();
    }
    //加载数据
    public void UpdatePanelInfo()
    {
        SoundData soundData = GameDataMgr.Instance.soundData;
        //设置面板内容
        sldMusic.nowValue = soundData.musicValue;
        sldSoundEffect.nowValue = soundData.soundEffectValue;
        togMusic.isSel = soundData.isOnMusic;
        togSoundEffect.isSel = soundData.isOnSoundEffect;
    }
    public override void ShowMe()
    {
        base.ShowMe();
        UpdatePanelInfo();
    }

}
